<template>
    <div>
      <div class="all" id="all">
        <div class="searchBox">
          <div class="aaa" id="aaa">
            <form action="javascript:;">
              <input type="text"
                     v-model="keyWord"
                     autofocus="autofocus"
                     :placeholder="this.$t('userHome.content.search.placeholder')"
                     autocomplete="off">
              <input type="submit" :value="this.$t('userHome.content.search.value')" id="subut" @click="toSearch">
            </form>
          </div>
          <a href="javascript:;" >
            <div class="backs" id="returns" @click="returns">×</div>
          </a>
        </div>
      </div>
      <div class="personalHome-bottom-box">
        <div class="personalHome-bottom-left" id="personalHome-bottom-left">
          <div class="content">
            <div class="content-head">
              <a href="javascript:;" :title="this.$t('userHome.content.return')">
                <div class="backHome" @click="recovery" id="backHome">
                  <i class="iconfont icon-return" style="font-size: 23px;" id="backHome-icon"></i>
                </div>
              </a>
              <div class="nav">
                <router-link :to="{path:'/userHomePage/error',query:{userId:this.$route.query.userId}}" :title="this.$t('userHome.content.navTitle01')">
                  <div v-if="this.component == 'error'" style="border-bottom: rgb(0, 168, 56) 2.3px solid;margin-left: 20px">
                    {{$t('userHome.content.navTitle01')}} <span>{{this.workCount.errorCount}}</span>
                  </div>
                  <div v-else style="border-bottom: transparent 2.3px solid;margin-left: 20px">
                    {{$t('userHome.content.navTitle01')}} <span>{{this.workCount.errorCount}}</span>
                  </div>
                </router-link>
                <router-link :to="{path:'/userHomePage/question',query:{userId:this.$route.query.userId}}" :title="this.$t('userHome.content.navTitle02')">
                  <div v-if="this.component == 'question'" style="border-bottom: rgb(0, 168, 56) 2.3px solid">
                    {{$t('userHome.content.navTitle02')}} <span>{{this.workCount.questionCount}}</span>
                  </div>
                  <div v-else style="border-bottom: transparent 2.3px solid">
                    {{$t('userHome.content.navTitle02')}} <span>{{this.workCount.questionCount}}</span>
                  </div>
                </router-link>
                <router-link :to="{path:'/userHomePage/blink',query:{userId:this.$route.query.userId}}" :title="this.$t('userHome.content.navTitle03')" >
                  <div @click="notDisplayBack" v-if="this.component == 'blink'" style="border-bottom: rgb(0, 168, 56) 2.3px solid">
                    {{$t('userHome.content.navTitle03')}} <span>{{this.workCount.blinkCount}}</span>
                  </div>
                  <div @click="notDisplayBack" v-else style="border-bottom: transparent 2.3px solid">
                    {{$t('userHome.content.navTitle03')}} <span>{{this.workCount.blinkCount}}</span>
                  </div>
                </router-link>
              </div>
              <a href="javascript:;" :title="this.$t('userHome.content.searchBtn')" v-if="this.component != 'blink'">
                <div class="search" id="search" @click="search">
                  <i class="iconfont icon-search" style="font-size: 30px;"></i>
                </div>
              </a>
            </div>
            <div class="content-body">
              <!-- 填充内容 -->
              <router-view @component="routerView" ref="target"></router-view>
            </div>
          </div>
          <div class="copyright">
            <a href="javascript:;"
               style="
               display: inline-block;
               color: #636363;
               width: 200px;
               height: 20px;
               margin: 0 auto;
               line-height: 20px;
               font-size: 12px;
               text-align: center;
               line-height: 20px;"
            >© 2022 StudiousTiger</a>
          </div>
        </div>
        <div class="personalHome-bottom-right" id="personalHome-bottom-right">
          <div class="personalHome-bottom-right-one">
            <div v-for="(item,index) in userData" :key="index" :title="$t('userHome.content.userAchievementTitle')" class="personalHome-bottom-right-one-sub">
              <div v-if="item.dataName == 'TA的粉丝'">{{$t('userHome.content.fans')}}</div>
              <div v-if="item.dataName == 'TA的关注'">{{$t('userHome.content.attentions')}}</div>
              <div v-if="item.dataName == 'TA的作品'">{{$t('userHome.content.works')}}</div>
              <div>{{item.counts}}</div>
            </div>

          </div>
          <div class="personalHome-bottom-right-two">
            <div class="personalHome-bottom-right-two-title">
              <i class="iconfont icon-rongyu" style="color: rgb(189, 30, 210);"> </i>
              {{$t('userHome.content.personalAchievementTitle')}}
            </div>
            <div class="personalHome-bottom-right-two-content">
              <div>
                <i class="iconfont icon-dianzan" style="color: rgb(243, 89, 0); margin-right: 10px;"></i>
                {{$t('userHome.content.dianzanAchievement', {count: userAchievement.qualityCount})}}
              </div>
              <div>
                <i class="iconfont icon-pinglun" style="color: rgb(0, 131, 192); margin-right: 10px;"></i>
                {{$t('userHome.content.pinglunAchievement', {count: userAchievement.replyCount})}}
              </div>
              <div>
                <i class="iconfont icon-shoucang2" style="color: rgb(226, 203, 0); margin-right: 10px;"></i>
                {{$t('userHome.content.shoucangAchievement', {count: userAchievement.collectedCount})}}
              </div>
            </div>
          </div>
          <div class="personalHome-bottom-right-three">
            <div class="personalHome-bottom-right-three-title">
              <i class="iconfont icon-cunchugui" style="color: rgb(30, 153, 210);"> </i>
                {{$t('userHome.content.goodCollection')}}
            </div>
            <div v-if="goodWorks.length != 0">
              <div v-for="(item,index) in goodWorks" :key="index" class="personalHome-bottom-right-three-content">
                <router-link target="_blank" :to="{path:'/worksDisplayPage',query:{workId:item.articleId}}">
                  <div>{{index+1}}. {{item.articleTitle}}</div>
                </router-link>
              </div>
            </div>
            <div v-else class="personalHome-bottom-right-three-content">
              <div>{{$t('userHome.content.nothing')}}</div>
            </div>

          </div>
          <div class="personalHome-bottom-right-four">
            <div class="block">
              <el-carousel height="180px">
                <el-carousel-item v-for="(item,index) in 4" :key="index">
                  <h3 class="small" style="margin-left: 130px">{{item}}</h3>
                </el-carousel-item>
              </el-carousel>
            </div>
          </div>
          <div class="personalHome-bottom-right-five">
            <h3 style="margin-left: 130px; margin-top: 80px; color: #8c939d">5</h3>
          </div>
        </div>
        <div id="tianchong"></div>
      </div>
    </div>
</template>

<script>
    export default {
        name: "UserContent",
        data(){
            return{
                baseURL:'http://localhost:8081/userHomePage/userWorksCount/',
                baseURL2:'http://localhost:8081/userHomePage/userData/',
                baseURL3:'http://localhost:8081/userHomePage/userAchievement/',
                baseURL4:'http://localhost:8081/userHomePage/userGoodWorks/',

                workCount:'',
                userData:'',
                userAchievement:'',
                goodWorks:'',

                component:'',

                keyWord:'',
            }
        },
        mounted(){
            this.getUserWorkCount()
            this.getUserData()
            this.getUserAchievement()
            this.getGoodWorks()
            window.addEventListener('scroll', this.scrollEvent,false)
        },
        methods: {
            recovery(){
                // 返回初始页
                if (this.keyWord != "") {
                    this.keyWord = ""
                    this.$refs.target.getWorksInfo();
                    this.notDisplayBack()
                }
            },
            toSearch(){
                if (this.keyWord.trim() != "") {
                    this.returns()
                    this.$refs.target.searchInfo(this.keyWord, this.$route.query.userId)
                    this.displayBack()
                }
            },

            notDisplayBack(){
                document.getElementById("backHome").style.width = "0px"
                document.getElementById("backHome").style.marginLeft = "0px"
                document.getElementById("backHome-icon").style.display = "none"
            },
            displayBack(){
                document.getElementById("backHome").style.width = "30px"
                document.getElementById("backHome").style.marginLeft = "20px"
                document.getElementById("backHome-icon").style.display = "block"
            },

            getUserWorkCount(){
              this.axios.post(this.baseURL+this.$route.query.userId).then(res=>{
                  if (res.data== false ){
                      this.$message.error(this.$('userHome.content.serviceUnusual'))
                  } else {
                      this.workCount = res.data
                  }
              }).catch(
                  exception=>{
                      console.log(exception)
                  }
              )
            },
            getUserData(){
              this.axios.post(this.baseURL2+this.$route.query.userId).then(res=>{
                  if (res.data=="false"){
                      this.$message.error(this.$('userHome.content.serviceUnusual'))
                  } else {
                      this.userData = res.data
                  }
              }).catch(
                  exception=>{
                      console.log(exception)
                  }
              )
            },
            getUserAchievement(){
              this.axios.post(this.baseURL3+this.$route.query.userId).then(res=>{
                  if (res.data=="false"){
                      this.$message.error(this.$('userHome.content.serviceUnusual'))
                  } else {
                      this.userAchievement = res.data
                  }
              }).catch(
                  exception=>{
                      console.log(exception)
                  }
              )
            },
            getGoodWorks(){
              this.axios.post(this.baseURL4+this.$route.query.userId).then(res=>{
                  if (res.data == "false"){
                      this.$message.error(this.$('userHome.content.serviceUnusual'))
                      alert(typeof res.data)
                  } else {
                      this.goodWorks = res.data
                  }
              }).catch(
                  exception=>{
                      console.log(exception)
                  }
              )
            },


            search() {
                document.getElementById("all").style.height = "100%";
                document.getElementById("aaa").style.marginTop = "250px";

            },
            returns() {
                document.getElementById("all").style.height = "0px";
                document.getElementById("aaa").style.marginTop = "0px"
            },
            // 监控滚动轴，当滚动轴滑动后，搜索框消失。
            scrollEvent(){
                let heig = parseInt(window.scrollY);
                if (heig > 0) {
                    this.returns()
                }
            },

            routerView(val){
                this.component = val
            },
        }
    }

</script>

<style scoped>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
    /*background-color: #99a9bf;*/
    background-color: #d3dce6;
  }

  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }


  .personalHome-bottom-box{
    width: 1150px;
    /* height: 500px; */
    margin: 10px auto;
    position: relative;
    letter-spacing: 1px;

  }
  .personalHome-bottom-left{
    float: left;
    width: 800px;
  }
  .content-head{
    width: 800px;
    height: 50px;
    background-color: rgba(255, 255, 255,0.9);
    border-radius: 3px;
    border: solid 1px rgb(224, 224, 224);
    position: relative;
  }
  .content-head .nav{
    float: left;
    width: 674px;
    text-align: center;
    margin: 0px auto;
  }
  .content-head .nav a div{
    float: left;
    color: rgb(85, 85, 85);
    font-size: 13px;
    font-weight: bold;
    min-width: 50px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    margin-left: 40px;
    margin-top: 12px;
    letter-spacing:1px;
  }
  .content-head .nav a div:hover{
    color: black;
  }
  .content-head .nav a:nth-child(1) div{
    margin-left: 30px;
  }
  .content-head .error{
    /*border-bottom: rgb(0, 168, 56) 2.3px solid;*/
    margin-left: 5px;
  }
  .content-head .blink{
    /*border-bottom: transparent 2.3px solid;*/
    margin-left: 5px;
  }
  .content-head div i{
    font-size: 10px;
  }
  .backHome, .search{
    float: left;
    width: 30px;
    height: 50px;
    line-height: 55px;
    margin-left: 20px;
  }
  .backHome{
    width: 0px;
    margin-left: 0px;
    transition: 0.3s;
    overflow: hidden;
  }
  .search{
    position: absolute;
    right: 10px;
  }
  .backHome i, .search i{
    color: rgb(97, 97, 97);
    font-weight:normal
  }
  .backHome i:hover, .search i:hover{
    font-weight: bolder;
  }
  .copyright{
    height: 50px;
    margin-top: 10px;
    margin-bottom: 20px;
    background-color: rgba(255,255,255,0.9);
    border-radius: 3px;
    border: solid 1px rgb(224, 224, 224);
    text-align: center;
    line-height: 50px;
    color: rgb(112, 112, 112);
    font-size: 10px;
  }
  .personalHome-bottom-right{
    float: left;
    width: 340px;
    margin-left: 10px;
    margin-bottom: 20px;
    /* background-color: tomato; */
  }
  .personalHome-bottom-right-one{
    height: 80px;
    border-radius: 3px;
    margin-bottom: 10px;
    letter-spacing:1px;
  }
  .personalHome-bottom-right-one-sub{
    width: 80px;
    height: 80px;
    background-color: rgba(255, 255, 255,0.9);
    border-radius: 3px;
    border: solid 1px rgb(237, 237, 237);
    transition: 0.2s;
    position: absolute;
  }
  .personalHome-bottom-right-one-sub:hover{
    box-shadow: 0 0 5px rgb(173, 173, 173);
  }
  .personalHome-bottom-right-one-sub:nth-child(1){
    margin-left: 0px;
  }
  .personalHome-bottom-right-one-sub:nth-child(2){
    margin-left: 125px;
  }
  .personalHome-bottom-right-one-sub:nth-child(3){
    margin-left: 255px;
  }
  .personalHome-bottom-right-one-sub div:nth-child(1){
    border-bottom: solid 1px rgb(223, 223, 223);
    line-height: 39px;
    text-align: center;
    font-size: 10px;
    font-weight: bolder;
    color: rgb(77, 77, 77);
  }
  .personalHome-bottom-right-one-sub div:nth-child(2){
    line-height: 39px;
    text-align: center;
    font-size: 10px;
    font-weight: bolder;
    color: #00695fc2;
  }
  .personalHome-bottom-right-two{
    /* height: 200px; */
    background-color: rgba(255, 255, 255,0.9);
    border-radius: 3px;
    margin-bottom: 10px;
  }
  .personalHome-bottom-right-two-title{
    height: 45px;
    line-height: 45px;
    border-bottom: 1px solid rgb(177, 177, 177);
    color: rgb(104, 104, 104);
    font-weight: bolder;
    font-size: 15px;
    padding-left: 10px;
    letter-spacing:1px;

  }
  .personalHome-bottom-right-two-content div{
    height: 35px;
    line-height: 35px;
    color: rgb(66, 66, 66);
    padding-left: 30px;
    font-size: 14px;
    letter-spacing:1px;

    /* 处理文字溢出 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;

  }
  .personalHome-bottom-right-three{
    /* max-height: 325px; */
    background-color: rgba(255, 255, 255,0.9);
    border-radius: 3px;
    margin-bottom: 10px;
    overflow: hidden;
  }
  .personalHome-bottom-right-three-title{
    height: 45px;
    line-height: 45px;
    border-bottom: 1px solid rgb(177, 177, 177);
    color: rgb(104, 104, 104);
    font-weight: bolder;
    font-size: 15px;
    padding-left: 10px;
    letter-spacing:1px;
  }
  .personalHome-bottom-right-three-content div{
    height: 35px;
    width: 310px;
    line-height: 35px;
    color: rgb(68, 68, 68);
    padding-left: 30px;
    font-size: 12px;
    letter-spacing:1px;
    transition: 0.2s;

    /* 处理文字溢出 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  .personalHome-bottom-right-three-content a i{
    color: rgb(61, 61, 61);
    margin-left: 200px;
  }
  .personalHome-bottom-right-three-content div:hover{
    color: black;
    font-size: 12.2px;
  }
  .personalHome-bottom-right-four{
    height: 180px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 3px;
    margin-bottom: 10px;
    overflow: hidden;
  }
  .personalHome-bottom-right-five{
    height: 180px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 3px;
    margin-bottom: 10px;
    overflow: hidden;
  }

  /* 搜索 */
  input{
    border: none;
    padding: 0px;
    border-right: none;
    padding-left: 10px;
  }
  .all {
    position: absolute;
    width: 100%;
    height: 0px;
    /* height: 600px; */
    background-color: rgba(0, 0, 0, 0.71);
    top: 0px;
    transition: 0.2s;
    overflow: hidden;
    z-index: 9999;
  }
  .searchBox{
    width: 800px;
    height: 200px;
    margin: -150px auto;
    position: relative;
  }
  .aaa {
    width: 350px;
    height: 50px;
    margin: 0px auto;
    transition: 0.8s;
  }
  input:nth-child(1){
    width: 300px;
    height: 40px;
    font-size: 18px;
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
    border: none;
    color: rgb(49, 49, 49);
    position: absolute;
    left: 220px;
    top: 100px;
  }
  input:nth-child(2){
    width: 50px;
    height: 40px;
    background-color: #4d8e90;
    color: white;
    font-size: 16px;
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
    border: none;
    position: absolute;
    left: 520px;
    top: 100px;
  }
  input:nth-child(2):hover{
    background-color: #00897b;
    font-size: 16px;

  }
  .backs{
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 30px;
    color: rgb(197, 197, 197);
    position: absolute;
    top: 0px;
    right: 100px;
  }
  .backs:hover{
    color: rgb(243, 243, 243);
  }
</style>
